﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Small.Express
{
    public static class DataPaingExtension
    {


       /// <summary>
       /// 分页
       /// </summary>
       /// <typeparam name="T"></typeparam>
       /// <param name="source"></param>
       /// <param name="page">页数</param>
       /// <param name="pagesize">页大小</param>
       /// <returns></returns>
       public static IQueryable<T> DataPaging<T>(this IQueryable<T> source, int page, int pagesize) 
       {
          IQueryable<T> query= source.Skip(pagesize * (page - 1)).Take(pagesize);


          return query;
       }
       /// <summary>
       /// 排序之后分页
       /// </summary>
       /// <typeparam name="T"></typeparam>
       /// <param name="source">数据源</param>
       /// <param name="sortField">排序字段</param>
       /// <param name="page">页数</param>
       /// <param name="pagesize">页大小</param>
       /// <param name="orderOptions"></param>
       /// <returns></returns>
       public static IQueryable<T> SortingAndPaging<T>(this IQueryable<T> source, String sortField, int page, int pagesize, OrderOptions orderOptions = OrderOptions.Asc) 
       {
           IQueryable<T> query = source.DynamicOrderBy<T>(sortField, orderOptions);

          return query.DataPaging<T>(page, pagesize);
       }
    }
}
